<?php

namespace app\modules\Admin\models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;

class orderModel extends Model
{
    protected $table = 'order';
    protected $primaryKey = 'id';
    protected $appends = ['paytime_text'];

    protected $hidden = ['paytime'];
    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function getPaytimeTextAttribute()
    {
        $paytime_text = '';

        if($this->attributes['paytime']){
            $paytime_text = date('Y-m-d H:i:s', $this->attributes['paytime']);
        }else{
            $paytime_text = '无支付时间';
        }

        return $paytime_text;
    }

    public function orderItems()
    {
        return $this->hasMany(orderItemModel::class, 'order_id', 'id');
    }
}